$(document).ready(function(){

    $("#login").click(function () {
        var name=$("#name").val();
        var password=$("#password").val();
        $.post("/artmanage/user/login", {name:name , password:password }, function (data) {
           if(data){
               window.location.href="/artmanage/index.html"
           }else{
               alert("账号或密码不正确")
               window.location.href="/artmanage/login.html"
           }
        })
    })
    $("#regist").click(function () {
        var rname=$("#rname").val()
        var rpassword=$("#rpassword").val()
        var flag1=false;
        var flag2=false;
         $.get("/artmanage/user/findbyname/"+rname,function (data) {
             if(data){
                 alert("姓名重复了")
             }else {
                 flag1=true;
             }
             if(rpassword.length<6){
                 alert("密码太短了")
             }else {
                 flag2=true
             }
             if(flag1&&flag2){
                 $.post("/artmanage/user/regist",{name:rname,password:rpassword},function (data) {
                     console.log(data)
                     if(data){

                         window.location.href="login.html"
                     }
                 })
             }
         })

    })

});